package com.lc202309;

import java.util.Arrays;

/**
 * Description:
 *
 * @Create 2023/9/18 20:36
 * @Version 1.0
 */
public class Solution6 {
    public String convert(String s, int numRows) {
        if (numRows < 2) {
            return s;
        }
        int index = 1;
        int direction = 1;
        String[] arr = new String[numRows];
        Arrays.fill(arr, "");
        for (int i = 0; i < s.length(); i++) {
            if (i == 0) {
                arr[index - 1] += s.charAt(i);
                index += direction;
                continue;
            }
            arr[index - 1] += s.charAt(i);
            if (index == numRows || index == 1) {
                direction = -direction;
            }
            index += direction;
        }
        return String.join("", arr);
    }
}
